#include <stdio.h>
#include <string.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>

int main()
{

    int fd = open("/dev/pts/0", O_WRONLY | O_APPEND);
    if (fd < 0) return 1;
    const char* message = "Haha\n";
    while (1)
    {
        write(fd, message, strlen(message));
        sleep(1);
    }

    close(fd);
    //while (1)
    //{
    //    printf("pid:%d\n", getpid());
    //    sleep(1);
    //}




    //printf("stdin->fd:%d\n", stdin->_fileno);
    //printf("stdout->fd:%d\n", stdout->_fileno);
    //printf("stderr->fd:%d\n", stderr->_fileno);


    //FILE *fp = fopen("log.txt", "w");
    //if (fp == NULL) return 1;

    //printf("fd:%d\n",fp->_fileno);
    //FILE *fp1 = fopen("log1.txt", "w");
    //if (fp == NULL) return 1;

    //printf("fd:%d\n",fp1->_fileno);
    //FILE *fp2 = fopen("log2.txt", "w");
    //if (fp == NULL) return 1;

    //printf("fd:%d\n",fp2->_fileno);

    //fwrite("Hello", 5, 1, fp);
    //fclose(fp);


    //const char* messaage = "Hello Linux File!\n";
    //write(1, messaage, strlen(messaage));

    //fprintf(stdout, "hello:%d\n", 10);


    //int fd1 = open("log1.txt", O_WRONLY | O_CREAT | O_TRUNC, 0666);
    //printf("fd1:%d\n", fd1);
    //int fd2 = open("log2.txt", O_WRONLY | O_CREAT | O_TRUNC, 0666);
    //printf("fd1:%d\n", fd2);
    //int fd3 = open("log3.txt", O_WRONLY | O_CREAT | O_TRUNC, 0666);
    //printf("fd1:%d\n", fd3);
    //int fd4 = open("log4.txt", O_WRONLY | O_CREAT | O_TRUNC, 0666);
    //printf("fd1:%d\n", fd4);

    //umask(0);
    ////int fd = open("log.txt", O_WRONLY | O_CREAT | O_TRUNC, 0666);
    //int fd = open("log.txt", O_WRONLY | O_CREAT | O_APPEND, 0666);
    //if (fd < 0)
    //{
    //    perror("open");
    //    return 1;
    //}

    //const char* messaage = "Hello Linux File!\n";
    ////const char* messaage = "abcdef\n";
    ////const char* messaage = "111";
    //write(fd, messaage, strlen(messaage));

    //close(fd);

    return 0;
}


//#define ONE   1
//#define TWO   (1<<1)
//#define THREE (1<<2)
//#define FOUR  (1<<3)
//#define FIVE  (1<<4)
//
//void print(int flag)
//{
//    if (flag&ONE)
//        printf("one\n");
//    if (flag&TWO)
//        printf("two\n");
//    if (flag&THREE)
//        printf("three\n");
//    if (flag&FOUR)
//        printf("four\n");
//    if (flag&FIVE)
//        printf("five\n");
//}
//
//int main()
//{
//    print(ONE);
//    printf("\n");
//    print(TWO);
//    printf("\n");
//    print(ONE|TWO);
//    printf("\n");
//    print(ONE|TWO|FIVE);
//
//
//    return 0;
//}


